package com.lagou.edu.connector.adapter;

import com.lagou.edu.connector.Endpoint;
import com.lagou.edu.connector.protocol.Processor;
import com.lagou.edu.container.Engine;

import java.util.concurrent.ThreadPoolExecutor;

/**
 * 请求适配器
 * <p>
 * 关联连接器和容器，将指定连接器接收到的请求参数传递到容器中进行处理
 *
 * @author liangzj
 * @date 2021/3/28 20:53
 */
public class Adapter {

    private Endpoint endpoint;
    private Engine engine;

    public Adapter(Endpoint endpoint, Engine engine) {
        this.endpoint = endpoint;
        this.engine = engine;
    }

    public void handleRequest() {
        ThreadPoolExecutor executor = endpoint.getExecutor();

        while (true) {
            executor.execute(new Processor(endpoint, engine));
        }
    }

}
